package com.joplus.housekeeper.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.joplus.housekeeper.R;
import com.joplus.housekeeper.bean.JoinVipBean;

import java.util.List;

/**
 * Created by ccm on 2016/9/30 14:34
 */
public class InRecycleAdapter extends BaseAdapter {

    private int positionW;
    private List<JoinVipBean.SpListBean.CategoryListBean> item;
    private Context mContext;
    private int level;

    InRecycleAdapter(Context mContext, List<JoinVipBean.SpListBean.CategoryListBean> item, int positionW, int level) {
        this.mContext = mContext;
        this.item = item;
        this.positionW = positionW;
        this.level = level;
    }

    @Override
    public int getCount() {
        return item.get(positionW).getServiceList().size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        holder holder = null;
        if (convertView == null) {
            holder = new holder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_joinvip2, null);
            holder.tv1 = (TextView) convertView.findViewById(R.id.item_joinvip_1);
            holder.tv2 = (TextView) convertView.findViewById(R.id.item_joinvip_2);
            convertView.setTag(holder);
        } else {
            holder = (InRecycleAdapter.holder) convertView.getTag();
        }
        if (level == 1) {

            holder.tv1.setText(item.get(positionW).getServiceList().get(position).getSerName());
            holder.tv2.setText(item.get(positionW).getServiceList().get(position).getEssContent());
            if (item.get(positionW).getServiceList().get(position).getEssStatus() == null || item.get(positionW).getServiceList().get(position).getEssStatus() == "0") {
                holder.tv1.setTextColor(Color.GRAY);
                holder.tv2.setTextColor(Color.GRAY);
            }
        } else if (level == 2) {
            holder.tv1.setText(item.get(positionW).getServiceList().get(position).getSerName());
            holder.tv2.setText(item.get(positionW).getServiceList().get(position).getPreContent());
            if (item.get(positionW).getServiceList().get(position).getPreStatus() == null || item.get(positionW).getServiceList().get(position).getPreStatus() == "0") {
                holder.tv1.setTextColor(Color.GRAY);
                holder.tv2.setTextColor(Color.GRAY);
            }
        } else if (level == 3) {
            holder.tv1.setText(item.get(positionW).getServiceList().get(position).getSerName());
            holder.tv2.setText(item.get(positionW).getServiceList().get(position).getBlackContent());
            if (item.get(positionW).getServiceList().get(position).getBlackStatus() == null || item.get(positionW).getServiceList().get(position).getBlackStatus() == "0") {
                holder.tv1.setTextColor(Color.GRAY);
                holder.tv2.setTextColor(Color.GRAY);
            }
        }
        return convertView;
    }

    static class holder {

        private TextView tv1;
        private TextView tv2;
    }
}
